<template>
  <div>
    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <el-select v-model="listselect"  placeholder="选择" clearable filterable @change="changelistselect(listselect)">
        <el-option v-for="item in listdata_l"
          :key="item.id"
          :label="item.title"
          :value="item.id">
        </el-option>
      </el-select>
      
    </el-card>
    
       <el-table :data="listdata_r" border stripe>
        <el-table-column 
          type="index"
          prop="col.id"
          label="序号"
          :width="80">
        </el-table-column>
        <el-table-column 
          prop="col.id"
          label="标题"
          width="width">
          <template slot-scope="{row,$index}">
            <div>
              {{ row.title }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="col.id"
          label="内容"
          width="width">
          <template slot-scope="{row,$index}" > 
            <div class="truncate">
              {{removeHTMLTags(row.content) }}
              
            </div>
          </template>
        </el-table-column>
        <el-table-column 
          prop="col.id"
          label="时间"
          width="width">
          <template slot-scope="{row,$index}">
            <div>
              {{ row.time }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="prop" label="操作" width="width">
          <template slot-scope="{ row, $index }">
            <div>
              <el-button
               v-show="row.isSale"
                type="success"
                size="mini"
                icon="el-icon-sort-up"
                circle
                @click="downdatashop(row)"
              ></el-button>
              <el-button
              v-show="! row.isSale"
                type="primary"
                size="mini"
                icon="el-icon-sort-down"
                circle
                @click="updatashop(row)"
              ></el-button>
             
              <el-button
                type="warning"
                size="mini"
                circle
                icon="el-icon-edit"
                @click="showshopdetail(row)"
              ></el-button>
              <el-button
                type="info"
                size="mini"
                circle
                icon="el-icon-info"
                @click="maintenance(row)"
              ></el-button>
              <el-button type="danger" size="mini" 
              circle icon="el-icon-delete" @click="deletebut(row)">

              </el-button>
              
            </div>
          </template>
        </el-table-column>
       </el-table>
       <el-drawer
      style="font-size: 30px;color: #000;"
      title="详细信息"
      :visible.sync="drawer"
      :direction="direction"
      size="50%"
      :before-close="handleClose">
  <!-- 名称 -->
<el-row>
  <el-col :span="10">标题</el-col>
</el-row>
<el-row>
  <el-input v-model="rrow.title " placeholder="输入标题.." size="normal" clearable ></el-input>
</el-row>
<!-- //描述 -->
<el-row>
  <el-col :span="10">内容</el-col>
</el-row>
<el-row>
  <el-input
  type="textarea"
  :rows="20"
  placeholder="输入内容.."
  v-model="showcontent">
</el-input>
</el-row>
<!-- 价格 -->
<el-row>
  <el-col :span="10">时间</el-col>
</el-row>
<el-row>
  <el-input v-model="rrow.time" placeholder="输入时间" size="normal" clearable ></el-input>
</el-row>
<el-row style=" display: flex;justify-content: center;">
  <el-button   type="success" size="default" @click="savecontent">保存</el-button>
  </el-row>
</el-drawer>
  </div>
</template>

<script>
export default {
  name: '',
  data(){
    return{
      listdata_r:[],
      listdata_l:[],
      listselect:"",
      isSale:true,
      drawer: false,//抽屉展示与隐藏
      direction: 'rtl',
      rrow:{},
      showcontent:""
    }
  },
  methods:{
    async updatashop(row){
      row.isSale = 1;
      // let result =await this.$API.sku.onsaveisshop(row.id)
      // if(result.code === 200){
      //   this.$message({type:"success",message:"成功上架"})
      // }
    },
    //下架数据的回调
    async downdatashop(row){
      row.isSale = 0;
      // let result=await this.$API.sku.downsaveisshop(row.id)
      // if(result.code === 200){
      //   this.$message({type:"warning",message:"已下架商品"})
      // }
    },
    showshopdetail(row){
      this.drawer=true;
      this.rrow = row;
      this.sendshowcontent(this.rrow.content)
      // let result =await this.$API.sku.getshowshopdetail(row.id)
      // console.log(result);
      // if(result.code === 200){
      //   this.showshopdetaildata = result.data
      // }
    },
    //展示动态内容展示:
    sendshowcontent(a){
     this.showcontent= this.removeHTMLTags(a);
    },
    //
    maintenance(row){
      this.$message("开发维护中...")
    },
    //删除按钮的回调
    deletebut(row){
      this.$message("暂时不支持删除...")
    },
    //清除所有HTML
    removeHTMLTags(html) {
      const replacedHtml = html.replace(/&nbsp;/g, ' ');
      return replacedHtml.replace(/<\/?[^>]+(>|$)/g, "");
    },
    async getlistdata(){
      let result = await this.$API.text.getAPIgetlistdata_lorr();
      if(result.code === 200){
        this.listdata_r = result.data.listdata_r;
        this.listdata_l = result.data.listdata_l;
      }
    },
    //课外数据id获取右侧数据
    async byleftlistdata(listselect){
      let result = await this.$API.text.byleftlistdata(listselect);
      if(result.code === 200){
        this.listdata_r = result.data.listdata_r;
      }
    },
    changelistselect(listselect){
      if(listselect){
         this.byleftlistdata(listselect);
      }
     else{
          this.getlistdata()
     }
    },
    //发起修改保存回调
    savecontent(){
      this.$message("开发维护中...")
    },
    //确认关闭？
    handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      }
  },
  mounted(){
    this.getlistdata()
  }
}
</script>

<style  scoped>
.truncate {
  overflow: hidden;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  width: 200px; /* 设置宽度 */
}
</style>
